package org.xq.softcup.mq.remoting.net;


import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xq.softcup.mq.remoting.net.params.BaseCallback;
import org.xq.softcup.mq.remoting.provider.XQRpcProviderFactory;
@Slf4j
public abstract class Server
{
    private BaseCallback startedCallback;
    private BaseCallback stopedCallback;

    public void setStartedCallback(BaseCallback startedCallback)
    {
        this.startedCallback = startedCallback;
    }

    public void setStopedCallback(BaseCallback stopedCallback)
    {
        this.stopedCallback = stopedCallback;
    }

    public abstract void start(XQRpcProviderFactory paramXQRpcProviderFactory) throws Exception;

    public void onStarted()
    {
        if (this.startedCallback != null) {
            try
            {
                this.startedCallback.run();
            }
            catch (Exception e)
            {
                log.error("启动失败.", e);
            }
        }
    }

    public abstract void stop()
            throws Exception;

    public void onStoped()
    {
        if (this.stopedCallback != null) {
            try
            {
                this.stopedCallback.run();
            }
            catch (Exception e)
            {
                log.error("服务停止回调服务失败.", e);
            }
        }
    }
}
